export const SessionStorage = {
  getItem: name => {
    const data = window.sessionStorage.getItem(name);
    try {
      return JSON.parse(data);
    } catch (err) {
      return data;
    }
  },
  setItem: (name, value) => {
    if (typeof value === "object") {
      value = JSON.stringify(value);
    }

    window.sessionStorage.setItem(name, value);
  },
  removeItem: name => {
    window.sessionStorage.removeItem(name);
  }
};

export const LocalStorage = {
  getItem: name => {
    const data = window.localStorage.getItem(name);
    try {
      return JSON.parse(data);
    } catch (err) {
      return data;
    }
  },
  setItem: (name, value) => {
    if (typeof value === "object") {
      value = JSON.stringify(value);
    }

    window.localStorage.setItem(name, value);
  },
  removeItem: name => {
    window.localStorage.removeItem(name);
  }
};
